
<style>
/*iscroll*/

.banner {width:100%;	margin:0 auto;padding:0;background-color:#151515;}
#wrapper {
	margin:0;width:100%;float:left;	position:relative;	/* On older OS versions "position" and "z-index" must be defined, */
	z-index:1;overflow:hidden;height: auto;margin: 0 auto;
}

#scroller {
	z-index: 1;	padding:0;-webkit-tap-highlight-color: rgba(0,0,0,0);	height: auto;
	-webkit-transform: translateZ(0);-moz-transform: translateZ(0);-ms-transform: translateZ(0);-o-transform: translateZ(0);transform: translateZ(0);
	-webkit-touch-callout: none;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;
	-webkit-text-size-adjust: none;-moz-text-size-adjust: none;-ms-text-size-adjust: none;-o-text-size-adjust: none;text-size-adjust: none;
	background-color: #FFF;
}

#scroller li {display:block; float:left;height:auto;text-align:center;font-size:0px;padding:0;position:relative;}
#scroller li img{max-width:100%;}
#scroller li a{	display:block;	padding:0;	margin:0;}
#scroller li p{
	position:absolute;z-index:2;	display:block;	width:100%;
	bottom:0;background-color:rgba(0, 0, 0, 0.5);color:#F4F4F4;	font-size:14px;	text-indent: 55px;	line-height:24px;
	text-align: left;text-indent: 10px;text-overflow: ellipsis;white-space: nowrap;	padding:0;margin:0;
}
#nav {float: right; margin-top: -15px;padding: 0;position: relative; width: auto;z-index: 3;}

#prev, #next {float:left;font-weight:bold;font-size:14px;padding:5px 0;width:80px;display: none;}

#next {float:right;text-align:right;}

#indicator > li {display:block; float:left;list-style:none;padding:0; margin:0;}

#indicator {display: block;margin: 0;padding: 0;width: auto;}

#indicator > li {text-indent:-9999em;width:8px; height:8px;-webkit-border-radius:4px;
	-moz-border-radius:4px;-o-border-radius:4px;border-radius:4px;background:#888;
	overflow:hidden;margin-right:4px;}

#indicator > li.active {background:#DDDDDD;}
#indicator > li:last-child {margin:0 8px 0 0;}

</style>

<div class="banner clearfix">
<div id="wrapper">
	<?php $banner_count = count($Wx['Uploadfile']['banner']); ?>
	<ul id="scroller" style="width:{{$banner_count}}00%;">
	{{loop $Wx['Uploadfile']['banner'] $key $file}}
		<li style="width:{{100/$banner_count}}%;"><p>{{$file['name']}}</p><a href="javascript:void(0)"><img src="{{$this->Html->image($file['fspath'],array('onlyurl'=>true))}}" /></a></li>
	{{/loop}}
	</ul>
</div>
  <div id="nav">
	<div id="prev" onclick="myScroll.scrollToPage('prev', 0,400,2);return false">&larr; prev</div>
	<ul id="indicator">
	      <li class="active" ></li><li  ></li><li  ></li>
	</ul>
	<div id="next" onclick="myScroll.scrollToPage('next', 0,400,2);return false">next &rarr;</div>
	</div>
    <div class="clr"></div>
</div>
{{$this->Html->script(array('iscroll.js', ))}}
<script type="text/javascript">

var myScroll;

var count = $("#scroller>li").size();
var slide_timeout,reset_timeout;

function loaded () {
	myScroll = new IScroll('#wrapper', {
		scrollX: true,
		scrollY: false,
		momentum: false,
		snapSpeed: 400,
		snap: true,
		keyBindings: true
	});
	
	slide_timeout = setTimeout(function(){
		myScroll.next();
	},5000 );
	
	myScroll.on('scrollEnd', function () {
		var pageX = this.currentPage.pageX;
		$('#indicator > li.active').attr('class','');
		$('#indicator > li:nth-child(' + (pageX+1) + ')').attr('class','active');
		clearTimeout(slide_timeout);//清空后再重建，防止手动切换后，切换时间间隔不同意
		if(pageX+1 == count){			
			reset_timeout = setTimeout(function(){			
				myScroll.goToPage(0, 0, 1000);
				$('#indicator > li.active').attr('class','');
				$('#indicator > li:nth-child(' + (1) + ')').attr('class','active');
				slide_timeout = setTimeout(function(){
					myScroll.next();
				},5000 )
				//slide_interval = setInterval(function(){
				//	myScroll.next();
				//},5000 );
			},5000 );
		}
		else{
			clearTimeout(reset_timeout);
			slide_timeout = setTimeout(function(){
				myScroll.next();
			},5000 )
		}
	});
}

//document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

document.addEventListener('DOMContentLoaded', loaded, false);

$(function(){
	
	$("#scroller>li").find("img").each(function(){
		 $(this).css('width',$('#wrapper').width())
	})
	$("#scroller").css('width',$('#wrapper').width()*count);

	window.onresize = function(){ 
		 $("#scroller>li").find("img").each(function(){
			 $(this).css('width',$('#wrapper').width())
		 })
		$("#scroller").css('width',$('#wrapper').width()*count);
	}
})


</script>

